/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author rodrigo
 */
@Entity
@Table(name = "Questao")
@NamedQueries({
    @NamedQuery(name = "Questao.findAll", query = "SELECT q FROM Questao q"),
    @NamedQuery(name = "Questao.findByQuestaoId", query = "SELECT q FROM Questao q WHERE q.questaoId = :questaoId")})
public class Questao implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "questao_id")
    private Integer questaoId;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "questao")
    private String questao;
    @JoinTable(name = "Questoes_Prova", joinColumns = {
        @JoinColumn(name = "questao_id", referencedColumnName = "questao_id")}, inverseJoinColumns = {
        @JoinColumn(name = "prova_id", referencedColumnName = "prova_id")})
    @ManyToMany
    private List<Prova> provaList;
    @JoinColumn(name = "autor_usuario_id", referencedColumnName = "usuario_id")
    @ManyToOne(optional = false)
    private Usuario autorUsuarioId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "questaoId")
    private List<Alternativa> alternativaList;

    public Questao() {
    }

    public Questao(Integer questaoId) {
        this.questaoId = questaoId;
    }

    public Questao(Integer questaoId, String questao) {
        this.questaoId = questaoId;
        this.questao = questao;
    }

    public Integer getQuestaoId() {
        return questaoId;
    }

    public void setQuestaoId(Integer questaoId) {
        this.questaoId = questaoId;
    }

    public String getQuestao() {
        return questao;
    }

    public void setQuestao(String questao) {
        this.questao = questao;
    }

    public List<Prova> getProvaList() {
        return provaList;
    }

    public void setProvaList(List<Prova> provaList) {
        this.provaList = provaList;
    }

    public Usuario getAutorUsuarioId() {
        return autorUsuarioId;
    }

    public void setAutorUsuarioId(Usuario autorUsuarioId) {
        this.autorUsuarioId = autorUsuarioId;
    }

    public List<Alternativa> getAlternativaList() {
        return alternativaList;
    }

    public void setAlternativaList(List<Alternativa> alternativaList) {
        this.alternativaList = alternativaList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (questaoId != null ? questaoId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Questao)) {
            return false;
        }
        Questao other = (Questao) object;
        if ((this.questaoId == null && other.questaoId != null) || (this.questaoId != null && !this.questaoId.equals(other.questaoId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Questao[ questaoId=" + questaoId + " ]";
    }
    
}
